<?php
class Branch extends Controller {
    public function index() {
        //$this->template->load('admintemplate', 'branch/index');
    }

    public function info() {
        //error_reporting(E_ALL);
        $division_id = $this->uri->segment(3);
        $branch_id = $this->uri->segment(4);

        $this->load->model("common_model");
        //$zone_info = $this->common_model->getZoneById($zone_id);
        $branch_info = $this->common_model->getBranchById($division_id, $branch_id);
        $data['branch_info'] = $branch_info;
        $data['division_id'] = $division_id;
        $data['branch_id'] = $branch_id;

        $branch_arr = $this->common_model->getBranchInfoById($division_id, $branch_id);
        $data['branch_arr'] = $branch_arr;

        $orgmeminfo = $this->common_model->getOrgMemInfo($division_id, $branch_id, 5); // 5 is Main org.
        $data['mainorgmeminfo'] = $orgmeminfo;

        $youthorgmeminfo = $this->common_model->getOrgMemInfo($division_id, $branch_id, 6); // 6 is Youth org.
        $data['youthorgmeminfo'] = $youthorgmeminfo;

        $womenorgmeminfo = $this->common_model->getOrgMemInfo($division_id, $branch_id, 7); // 7 is Women org.
        $data['womenorgmeminfo'] = $womenorgmeminfo;

        $this->template->load('template', 'branchinfo', $data);
    }

    public function compare()
    {
        $this->load->model("common_model");

        $udapaltha_arr = $this->common_model->getBranchDetailsByDivisionId(1);
        $udapalthamc_arr = $this->common_model->getBranchDetailsByDivisionId(2);
        $doluwa_arr = $this->common_model->getBranchDetailsByDivisionId(3);

        $data['udapaltha_arr'] = $udapaltha_arr;
        $data['udapalthamc_arr'] = $udapalthamc_arr;
        $data['doluwa_arr'] = $doluwa_arr;

        $this->template->load('template', 'compare', $data);
    }

    public function showbranchtocompare()
    {
        $this->load->model("common_model");
        $branch_id = $_POST['branchid'];
        $division_id = $_POST['divisionid'];

        $branch_arr = $this->common_model->getBranchInfoById($division_id, $branch_id);
        //$data['branch_arr'] = $branch_arr;
?>
        <div class="section-01 st">
        <table id="hor-minimalist-b" summary="" style="width: 220px !important;">
            <thead>
            <tr>
                <th width="80" scope="col">Category</th>
                <th width="40" scope="col">Value</th>
            </tr>
            </thead>
            <tbody>
<?php
            foreach ($branch_arr as $_data) :
                if($_data['populationcatdesc'] == "sinhalese")
                    $sinhalese = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "srilankan_tamil")
                    $srilankan_tamil = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "indian_tamil")
                    $indian_tamil = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "muslim")
                    $muslim = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "other_nat")
                    $other_nat = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "buddhist")
                    $buddhist = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "catholic")
                    $catholic = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "islam")
                    $islam = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "hindu")
                    $hindu = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "other_rel")
                    $other_rel = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "male")
                    $male = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "female")
                    $female = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "age_1_16")
                    $age_1_16 = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "age_16_30")
                    $age_16_30 = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "age_30_50")
                    $age_30_50 = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "age_50")
                    $age_50 = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "votees")
                    $votees = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "area")
                    $area = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "population")
                    $population = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "house_units")
                    $house_units = $_data['TOTALCOUNT'];
                if($_data['populationcatdesc'] == "samurdi_families")
                    $samurdi_families = $_data['TOTALCOUNT'];


            endforeach;
?>

            <tr>
                <td>Sinhalese</td>
                <td><?php echo $sinhalese; ?></td>
            </tr>
            <tr>
                <td>Sri Lankan Tamil</td>
                <td><?php echo $srilankan_tamil; ?></td>
            </tr>
            <tr>
                <td>Indian Tamil</td>
                <td><?php echo $indian_tamil; ?></td>
            </tr>
            <tr>
                <td>Muslim</td>
                <td><?php echo $muslim; ?></td>
            </tr>
            <tr>
                <td>Other</td>
                <td><?php echo $other_nat; ?></td>
            </tr>
            <tr>
                <td class="td-style01" style="border-bottom:none;" >Total</td>
                <td class="td-style01" style="border-bottom:none;" >
                    <?php
                    $total_nat = $sinhalese + $srilankan_tamil + $indian_tamil + $muslim + $other_nat;
                    echo $total_nat; // do not delete
                    ?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="section-01">
        <table id="hor-minimalist-b" summary="" style="width: 220px !important;">
            <!--<thead>
            <tr>
                <th width="80" scope="col">Category</th>
                <th width="40" scope="col">Amount</th>
            </tr>
            </thead>-->
            <tbody>
            <tr>
                <td>Buddhist</td>
                <td><?php echo $buddhist; ?></td>
            </tr>
            <tr>
                <td>Catholic</td>
                <td><?php echo $catholic; ?></td>
            </tr>
            <tr>
                <td>Hindu</td>
                <td><?php echo $hindu; ?></td>
            </tr>
            <tr>
                <td>Islam</td>
                <td><?php echo $islam; ?></td>
            </tr>
            <tr>
                <td>Other</td>
                <td><?php echo $other_rel; ?></td>
            </tr>
            <tr>
                <td class="td-style01" style="border-bottom:none;" >Total</td>
                <td class="td-style01" style="border-bottom:none;" >
                    <?php
                    $total_rel = $buddhist + $catholic + $hindu + $islam + $other_rel;
                    echo $total_rel; // do not delete
                    ?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="section-01 st">
        <table id="hor-minimalist-b" summary="" style="width: 220px !important;">
            <!--<thead>
            <tr>
                <th width="80" scope="col">Category</th>
                <th width="40" scope="col">Amount</th>
            </tr>
            </thead>-->
            <tbody>
            <tr>
                <td>Male</td>
                <td><?php echo $male; ?></td>
            </tr>
            <tr>
                <td>Female</td>
                <td><?php echo $female; ?></td>
            </tr>
            <tr>
                <td class="td-style01" style="border-bottom:none;" >Total</td>
                <td class="td-style01" style="border-bottom:none;" >
                    <?php
                    $total_gen = $male + $female;
                    echo $total_gen; // do not delete
                    ?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="section-01">
        <table id="hor-minimalist-b" summary="" style="width: 220px !important;">
            <!--<thead>
            <tr>
                <th width="80" scope="col">Category</th>
                <th width="40" scope="col">Amount</th>
            </tr>
            </thead>-->
            <tbody>
            <tr>
                <td>1-16</td>
                <td><?php echo $age_1_16; ?></td>
            </tr>
            <tr>
                <td>16-30</td>
                <td><?php echo $age_16_30; ?></td>
            </tr>
            <tr>
                <td>30-50</td>
                <td><?php echo $age_30_50; ?></td>
            </tr>
            <tr>
                <td>50 above</td>
                <td><?php echo $age_50; ?></td>
            </tr>
            <tr>
                <td class="td-style01" style="border-bottom:none;" >Total</td>
                <td class="td-style01" style="border-bottom:none;" >
                    <?php
                    $total_age = $age_1_16 + $age_16_30 + $age_30_50 + $age_50;
                    echo $total_age;
                    ?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="section-01">
        <table id="hor-minimalist-b" summary="" style="width: 220px !important;">
            <!--<thead>
            <tr>
                <th width="80" scope="col">Category</th>
                <th width="40" scope="col">Amount</th>
            </tr>
            </thead>-->
            <tbody>
            <tr>
                <td width="85">Votees</td>
                <td width="35"><?php echo ($votees != "")?$votees:"-"; ?></td>
            </tr>
            <tr>
                <td>Area</td>
                <td><?php echo ($area != "")?$area:"-"; ?></td>
            </tr>
            <tr>
                <td>Population</td>
                <td><?php echo ($population != "")?$population:"-"; ?></td>
            </tr>
            <tr>
                <td>House Units</td>
                <td><?php echo ($house_units != "")?$house_units:"-"; ?></td>
            </tr>
            <tr>
                <td>Samurdhi Beneficiaries</td>
                <td><?php echo ($samurdi_families != "")?$samurdi_families:"-"; ?></td>
            </tr>
            </tbody>
        </table>
    </div>
 <?php
    }

}
?>